package com.example.task1.ui.AllService.library;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.LibraryBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class LibraryAdapter extends BaseAdapter<LibraryBean.RowsDTO> {

    private Context context;
    private List<LibraryBean.RowsDTO> mData = new ArrayList<>();
    private ImageView image;
    private TextView tvName;
    private TextView tvAddress;
    private TextView tvTime;

    public LibraryAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected void setData(List<LibraryBean.RowsDTO> rows) {
        int size = mData.size();
        mData.addAll(rows);
        notifyItemInserted(size);
    }

    @Override
    protected int getLayout() {
        return R.layout.librarylist;
    }

    @Override
    protected Context getContext() {
        return null;
    }

    @Override
    protected List<LibraryBean.RowsDTO> getData() {
        return mData;
    }

    @Override
    protected void onBind(myHolder holder, LibraryBean.RowsDTO date) {
        MyApplication.glide(image, date.getImgUrl());
        tvName.setText(date.getName());
        tvAddress.setText(date.getAddress());
        tvTime.setText(date.getBusinessHours());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.intent(context, LibraryDetailActivity.class, date.getId());
            }
        });
    }

    @Override
    protected void holder(View view) {
        initView(view);
    }

    private void initView(View view) {
        image = view.findViewById(R.id.image);
        tvName = view.findViewById(R.id.tv_name);
        tvAddress = view.findViewById(R.id.tv_address);
        tvTime = view.findViewById(R.id.tv_time);
    }
}
